package com.ftg.learn.util;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 分页插件
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/4/4 上午10:40
 */
@Configuration
public class MybatisPlusPageInterceptorConfig {

    /**
     * 使用MybatisPlusInterceptor 插件
     *    注入 物理分页插件
     * @return
     */
    @Bean
    public MybatisPlusInterceptor initPageInterceptor(){
        MybatisPlusInterceptor p = new MybatisPlusInterceptor();
        PaginationInnerInterceptor p1 = new PaginationInnerInterceptor();
        p1.setDbType(DbType.MYSQL);
        //分页
        p.addInnerInterceptor(p1);
        //乐观
        p.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return p;
    }


}
